/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ortus.daemon;

import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author jphipps
 */
public class tcpDaemon extends Thread {
	private int Port = 6666;
	private Thread_pool pool;

	public tcpDaemon() {
		pool = new Thread_pool(10,10);
		ortus.api.DebugLog(ortus.ortusvars.INFO, "tcpDaemon: Loading");
	}

	public void run() {
		ortus.api.DebugLog(ortus.ortusvars.INFO, "tcpDaemon: Running");
		try {
		     ortus.api.DebugLog(ortus.ortusvars.INFO,"tcpDaemon: Command processor listening on port " + Port);
		     ServerSocket serverSocket = new ServerSocket(Port);
		     while(true) {
			Socket socket = serverSocket.accept();
			pool.execute(new serverWorker(socket));
		      }
		} catch (Exception ex) {
			ortus.api.DebugLog(ortus.ortusvars.ERROR, "tcpDaemon: exception: " + ex);
		}
		ortus.api.DebugLog(ortus.ortusvars.INFO,"tcpDaemon: Stopping");
	}

	public void Shutdown() {
	}
}
